# 这个脚本是为了构建基础缓存（
# 运行时机：需要更新缓存的时候
# 运行位置：一般只要本地运行即可

# 设置基本信息
timestamp="$(date +%Y%m%d%H%M)"
branch=${GIT_LOCAL_BRANCH:-$(git rev-parse --abbrev-ref HEAD)}
echo "${branch}"
project_name=namespace-name
repo_name=server-name
docker_reg=""
package_name=api

image_full_name="${repo_name}-${package_name}:${branch}-${timestamp}"

# 登录
docker login -u "$USERNAME" -p "$PASSWORD" "$docker_reg"

# 构建镜像
docker build -t "${image_full_name}" -f cache.Dockerfile .
if [ $? != 0 ]; then
  exit 1
fi

# 上传镜像到仓库
 docker tag "${image_full_name}" "${docker_reg}"/"${image_full_name}"
 docker push "${docker_reg}"/"${image_full_name}"


echo "在需要缓存的镜像使用"
echo "FROM ${docker_reg}/${image_full_name} as base"
